/**
 * Copyright (c) 2008 michiyasu wada
 * http://www.seyself.com/
 * 
 * Distributed under The MIT License.
 * [http://www.opensource.org/licenses/mit-license.php]
 *
 * @author michiyasu wada / michi@seyself.com
 */


class flash.utils.Dictionary
{

    public function Dictionary()
    {
        container = [];
    }

    public function get length():Number
    {
        return container.length;
    }

    public function value( key:Object ):Object
    {
        var con = container;
        var len = con.length;
        for(var i:Number=0;i<len;i++){
            var res = con[i].check( key );
            if( res ) return res.data;
        }
        return null;
    }

    public function add( key:Object, value:Object ):Void
    {
        container.push( _add( key, value ) );
    }

    public function has( key:Object ):Boolean
    {
        var con = container;
        var len = con.length;
        for(var i:Number=0;i<len;i++){
            if( con[i].has( key ) ) return true;
        }
        return false;
    }

    public function del( key:Object ):Void
    {
        var con = container;
        var len = con.length;
        for(var i:Number=0;i<len;i++){
            if ( con[i].has( key ) ) {
                con.splice( i , 1 );
                break;
            }
        }
    }

    public function toString():String
    {
        return "[object Dictionary]";
    }

    //--------------------------------------------------------------------------
    //
    //  PRIVATE
    //
    //--------------------------------------------------------------------------

    private var container:Array;

    private function _add( obj, value ):Object
    {
        var dic = {};
        dic.check = function( key )
        {
            if (obj == key) return { data:value };
            return undefined;
        }
        dic.has = function( key ):Boolean
        {
            if (obj == key) return true;
            return false;
        }
        return dic;
    }




}
